<?php

namespace App\Models\Settings;

use App\Models\BaseModel;

class Code extends BaseModel
{
    protected $table = 'settings__codes';

    const MODULE_KEY = 'settings__code_module';

    /**
     * 字段
     * @var array
     */
    protected $fillable = [
        'id',
        'module',
        'name',
        'code',
        'desc',
        'deleted_at',
        'updated_at',
        'created_at'
    ];

    public function getModuleTextAttribute($val)
    {
        return $this->getCode(self::MODULE_KEY, $val);
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function values()
    {
        return $this->hasMany(CodeValue::class, 'code', 'code');
    }
}
